/**
 * Created by wangzhuoya on 2017/8/9.
 */

var iframeLoaded = function (iframe) {
    if (iframe.src.length > 0) {
        if (!iframe.readyState || iframe.readyState == "complete") {
            var bHeight =
                iframe.contentWindow.document.body.scrollHeight;
            var dHeight =
                iframe.contentWindow.document.documentElement.scrollHeight;
            var height = Math.max(bHeight, dHeight);
            iframe.height = height;
        }
    }
}

var reSetIframeHeight = function() {
    try {
        var oIframe = parent.document.getElementById(window.name);
        oIframe.height = 100;
        iframeLoaded(oIframe);
    }
    catch (err) {
        try {
            parent.document.getElementById(window.name).height = 1000;
        } catch (err2) { }
    }
}


/**
 * 显示提示框
 */
function showMsg(msg) {
    $.gritter.add({
        title: '提示',
        text: msg,
        time: 2500
    });
}


//页面跳转.
function skip(url) {
    window.location.href = url;
}

//调整窗口大小
var debounce = function (func, threshold, execAsap) {
    var timeout;
    return function debounced () {
        var obj = this, args = arguments;
        function delayed () {
            if (!execAsap)
                func.apply(obj, args);
            timeout = null;
        };
        if (timeout)
            clearTimeout(timeout);
        else if (execAsap)
            func.apply(obj, args);
        timeout = setTimeout(delayed, threshold || 100);
    };
}

window.onresize = debounce(function(){
    reSetIframeHeight();
}, 100, true)